//
//  UIWidget.h
//  storm
//
//  Created by wangdi on 13-8-1.
//
//

#ifndef __CocosLib__UIWidget__
#define __CocosLib__UIWidget__

#include "cocos2d.h"
#include "../ThirdLib/sigslot/sigslot.h"
#include <list>
#include <queue>

namespace storm
{
    typedef sigslot::has_slots<> UIListener;
    
    class UIWidget : public cocos2d::CCLayer
    {
    protected:
        static UIWidget *s_pFocusWidget;
        
    public:
        virtual void setEnable(bool bEnable) {m_bEnable = bEnable;}
        virtual void loseFocus()			 {if(s_pFocusWidget == this) s_pFocusWidget = NULL;}
        
        virtual bool isContainsTouch(cocos2d::CCTouch *pTouch);
        
        // transform node funs
        virtual void fadeOutNodes(float duration);
        virtual void fadeInNodes(float duration);
        virtual void scaleNodes(float scale);
        virtual void opacityNodes(float opacity);
    public:
        virtual UIWidget *onReceiveNewTouch(cocos2d::CCTouch *pTouch) {return NULL;}
        virtual void onCurTouchMoveOut(cocos2d::CCTouch *pTouch) {}
        virtual void onCurTouchMoving(cocos2d::CCTouch *pTouch)  {}
        virtual void onCurTouchFinish(cocos2d::CCTouch *pTouch) {}
        
    public:
        UIWidget();
        virtual ~UIWidget();

        bool IsEnable() const {return m_bEnable;}
        void SetData(bool bEnable = true) {m_bEnable   = bEnable;}
        
        void AddTransformNode(cocos2d::CCNode *pNode) {m_transformNodes.push_back(pNode);}
        void RemoveTransformNode(cocos2d::CCNode *pNode) {m_transformNodes.remove(pNode);}
    protected:
        bool              m_bEnable;
        std::list<cocos2d::CCNode *> m_transformNodes;
    };
    
    typedef std::list<UIWidget *> WidgetList;
    typedef std::queue<UIWidget *>  WidgetQueue;
    typedef std::vector<UIWidget *> WidgetVector;
    typedef std::list<cocos2d::CCNode *> TransformNodes;
}
#endif /* defined(__CocosLib__UIWidget__) */
